# Adam Wilson http://brilliant.org/competitions/hunger-games/ August 12, 2013

# My approach is to maximize the amount of slacking while hunting enough
# to avoid being a freeloader.  I take for granted that other players will
# be on the lookout for freeloaders that would take advantage of them, but
# also for likely hunters to take advantage of.  Thus I try to maintain a middle
# ground by slacking when it appears likely that the group will incur a bonus for
# meeting the threshold set by M each round.  If it seems unlikely that the group
# will meet the threshold, I then base my actions off a Tit-for-Tat strategy.

# To decide if M will be met, or surpassed, I maintain a list (all_hunters) of the number of
# players in the game at the start of each round.  With this list and the round
# number, I iterate through all my fellow tribesmen to calculate the likely amount
# of hunts they will engage in this round. Since a tribemen's reputation is the
# ratio of hunts to opportunities to hunt (H+S), I can work backwards by multiplying
# their reputation by the total number of possible hunts so far (the sum of all_hunters) to
# arrive at the number of hunts he/she has engaged in, and divide by the round
# number to find how many times they've hunted per round.  By adding up all the
# hunts_per_rounds for each tribe member I obtain an estimate of the total number of hunts
# to occur this round.  If that number exceeds or is equal to M, I invariably slack and obtain
# either 3 or 0 food for each round, due to the bonus, if it is realized.

# If M is not met, then I iterate through each tribe member and use their reputation
# as a threshold for my own likelihood of hunting with them.  By generating a number
# randomly between 0 and 1, if their reputation is higher than or equal to the
# random number, then I hunt and otherwise I slack.  In other words, the more likely they
# are to choose to hunt, the more likely that I am also.

# The downfall of this strategy is that I don't factor my own reputation into the
# decision making process if M is not met.  If my reputation is low, it seems
# probable that my hunting partners will slack to avoid getting taken advantage of.
# However, I am new to computer programming and python, so I am sticking with this
# simple strategy.  I hope it survives the Hunger Games! Thank you Brilliant.org for putting
# on this event.

import random

all_hunters = []

def hunt_choices(round_number, current_food, current_reputation, m,  player_reputations):
    
    hunters = len(player_reputations)
    all_hunters.append(hunters)

    total_hunts_per_round = 0
    for tribesman in player_reputations:
        hunts_per_round = (tribesman * sum(all_hunters))/round_number
        total_hunts_per_round += hunts_per_round

    if total_hunts_per_round >= m:
        return ['s']*len(player_reputations)
    else:
        hunt_decisions = []
        for tribesman in player_reputations:
            if random.random() <= tribesman and tribesman != 0:
                hunt_decisions.append('h')
            else:
                hunt_decisions.append('s')
        return hunt_decisions

    return hunt_decisions;

def hunt_outcomes(food_earnings):
    pass 

def round_end(award, m, number_hunters):
    pass
